from PySide6.QtCore import QObject, Property, Signal, QPointF
from PySide6.QtGui import QColor

from PySide6.QtQuick import (QQuickItem, QSGFlatColorMaterial,
                             QSGGeometry, QSGGeometryNode, QSGNode)
from PySide6.QtQml import QmlElement
from enum import Enum
import logging
QML_IMPORT_NAME = "BppTable"
QML_IMPORT_MAJOR_VERSION = 1
# class ColumnType(Enum):
#     Str = 0
#     Dbl=1
#     Int=2
#     Date=3
#     DateTime=4

@QmlElement
class BTColumn(QObject):
    Str = 0
    Dbl=1
    Int=2
    Date=3
    DateTime=4
    def __init__(self,parent=None):
        super().__init__(parent)
        self.type="string"
        self.view=0
        self.sortFlag=0
        self.action=0
        self.command=0
        self.width=0
        self.minWidth=0
        self.visible=True
        self.reference1=-1
        self.dataRef1=None
        self.title=""

    def modify(self,colDef, withDefaults):
        logging.info("modify")
        if(colDef.get("width") is None):
            if(withDefaults): 
                self.width = 100
        else:
            self.width = int(colDef["width"])
        
        if(self.width == 0):
            self.width = 100;

        if(colDef.get("minWidth") is None):
            if(withDefaults):
                self.minWidth = 0;
        else:
            self.minWidth = int(colDef["minWidth"])

        if(colDef.get("title") is None):
            if(withDefaults):
                self.title = ""
        else:
            self.title = str(colDef["title"])

        if(colDef.get("sort") is None):
            if(withDefaults): 
                self.sortFlag = 0
        else:
            self.sortFlag = int(colDef["sort"])

        if(colDef.get("dataType") is None):
            if(withDefaults):
                self.type = "string"
        else:
            self.type = ColumnType( int(colDef["dataType"]))

        if(colDef.get("view") is None):
            if(withDefaults): 
                self.view = 0
        else:
            self.view = int(colDef["view"])
        self.command=colDef.get("command",0)
        self.role=colDef.get("role","")
        self.visible=colDef.get("visible",True)
        self.dataRef1=colDef.get("dataRef1","")
